package com.ruoyi.fantasy.service.impl;

import java.util.List;
import java.util.Map;

import com.huanzhidadi.fantasy.bean.domain.FantasyShop;
import com.ruoyi.fantasy.common.WorldInit;
import com.ruoyi.fantasy.domain.FantasyShopBO;
import com.ruoyi.system.domain.SysUser;
import org.springframework.stereotype.Service;
import com.ruoyi.fantasy.mapper.FantasyShopMapper;
import com.ruoyi.fantasy.service.IFantasyShopService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 商店 服务层实现
 * 
 * @author wanghui
 * @date 2020-01-29
 */
@Service
public class FantasyShopServiceImpl implements IFantasyShopService 
{
	@Resource
	private FantasyShopMapper fantasyShopMapper;

	/**
     * 查询商店信息
     * 
     * @param id 商店ID
     * @return 商店信息
     */
    @Override
	public FantasyShop selectFantasyShopById(Long id)
	{
	    return fantasyShopMapper.selectFantasyShopById(id);
	}
	
	/**
     * 查询商店列表
     * 
     * @param fantasyShop 商店信息
     * @return 商店集合
     */
	@Override
	public List<FantasyShop> selectFantasyShopList(FantasyShop fantasyShop)
	{
	    return fantasyShopMapper.selectFantasyShopList(fantasyShop);
	}
	
    /**
     * 新增商店
     * 
     * @param fantasyShop 商店信息
     * @return 结果
     */
	@Override
	public int insertFantasyShop(FantasyShop fantasyShop)
	{
	    return fantasyShopMapper.insertFantasyShop(fantasyShop);
	}
	
	/**
     * 修改商店
     * 
     * @param fantasyShop 商店信息
     * @return 结果
     */
	@Override
	public int updateFantasyShop(FantasyShop fantasyShop)
	{
	    return fantasyShopMapper.updateFantasyShop(fantasyShop);
	}

	/**
     * 删除商店对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteFantasyShopByIds(String ids)
	{
		return fantasyShopMapper.deleteFantasyShopByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<FantasyShop> selectAllocatedList(FantasyShopBO fantasyShopBO) {
		return fantasyShopMapper.selectAllocatedList(fantasyShopBO);
	}

	@Override
	public void transforData(List<FantasyShop> list) {
		Map<String, SysUser> sysUserMap = WorldInit.sysUserMap;
		for (FantasyShop fantasyShop : list) {
			if (fantasyShop.getCreateBy() != null) {
				if (sysUserMap.get(fantasyShop.getCreateBy()) != null) {
					fantasyShop.setCreateBy(sysUserMap.get(fantasyShop.getCreateBy()).getUserName());
				} else {
					fantasyShop.setCreateBy("系统管理员");
				}
			}
			if (fantasyShop.getUpdateBy() != null) {
				if (sysUserMap.get(fantasyShop.getUpdateBy()) != null) {
					fantasyShop.setUpdateBy((sysUserMap.get(fantasyShop.getUpdateBy()).getUserName()));
				} else {
					fantasyShop.setUpdateBy("系统管理员");
				}
			}
			//禁用标记
			if (fantasyShop.getDelFlag().equals("0")) {
				fantasyShop.setDelFlag("正常");
			} else if (fantasyShop.getDelFlag().equals("1")) {
				fantasyShop.setDelFlag("禁用");
			}
		}

	}

	@Override
	public List<FantasyShop> selectUnallocatedList(FantasyShopBO fantasyShopBO) {
		return fantasyShopMapper.selectUnallocatedList(fantasyShopBO);
	}

}
